package cn.tedu.tmall.front.content.service.impl;

import cn.tedu.tmall.front.content.persist.respository.ICategoryRepository;
import cn.tedu.tmall.front.content.pojo.po.CategoryPO;
import cn.tedu.tmall.front.content.pojo.vo.CategoryVo;
import cn.tedu.tmall.front.content.service.ICategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class CategoryServiceImpl implements ICategoryService {

    @Autowired
    private ICategoryRepository categoryRepository;

    @Override
    public List<CategoryVo> listCategory() {
        List<CategoryPO> categoryPOS = categoryRepository.listCategory();
        List<CategoryVo> result = new ArrayList<>();
        for (CategoryPO categoryPO : categoryPOS) {
            CategoryVo categoryVo = new CategoryVo();
            BeanUtils.copyProperties(categoryPO,categoryVo);
            result.add(categoryVo);
        }
        return result;

    }
}
